package com.springboot.dto;

import com.alibaba.fastjson.annotation.JSONField;

import java.io.Serializable;

public class ResultModel<T> extends Result<T> implements Serializable{

    //常用变量
    public static String SUCCESS = "success";
    public static String SUCCESS_CODE = "200";
    public static String SUCCESS_DEFAULT_COUNT = "1";
    public static String SUCCESS_DEFAULT_MSG = "成功";
    public static String ERROR = "error";
    public static String ERROR_CODE = "500";
    public static String ERROR_DEFAUL_COUNT = "0";
    public static String ERROR_DEFAULT_MSG = "失败";


    public ResultModel(String result, String msg, String count, T data, String code) {
        super(result, msg, count, data, code);
    }
    public ResultModel(){
        super();
    }

    @JSONField(serialize = false)
    public boolean isSuccess() {
        return SUCCESS.equals(getResult());
    }

    /**
     * 成功返回
     *
     * @param count
     * @param data
     * @param msg
     * @return
     */
    public static <T> ResultModel<T> successResult(String count, String msg, T data) {
        return new ResultModel<T>(ResultModel.SUCCESS, msg,count, data,  ResultModel.SUCCESS_CODE);
    }
    public static <T> ResultModel<T> successResult(String count, T data) {
        return new ResultModel<T>(ResultModel.SUCCESS,SUCCESS_DEFAULT_MSG,count, data, ResultModel.SUCCESS_CODE);
    }
    public static <T> ResultModel<T> successResult(T data) {
        return new ResultModel<T>(ResultModel.SUCCESS,SUCCESS_DEFAULT_MSG,SUCCESS_DEFAULT_COUNT, data, ResultModel.SUCCESS_CODE);
    }
    public static <T> ResultModel<T> successResult(String count, String msg) {
        return new ResultModel<T>(ResultModel.SUCCESS, msg,count, null,  ResultModel.SUCCESS_CODE);
    }

    /**
     * 失败返回
     *
     * @param count
     * @param data
     * @param msg
     * @return
     */
    public static <T> ResultModel<T> errorResult(String errorCode, String errorMsg) {
        return new ResultModel<T>(ResultModel.ERROR,errorMsg, ResultModel.ERROR_DEFAUL_COUNT,null,errorCode);
    }
    public static <T> ResultModel<T> errorResult(String errorMsg) {
        return new ResultModel<T>(ResultModel.ERROR,errorMsg, ResultModel.ERROR_DEFAUL_COUNT,null, ResultModel.ERROR_CODE);
    }


}

